Mi código es así:
$(document).ready(function () { size_li = $("#myList li").length(); x=3; $('#myList li:lt('+x+')').show(); $('#loadMore').click(function () { x= (x+5 <= size_li) ? x+5 : size_li; $('#myList li:lt('+x+')').show(); }); $('#showLess').click(function () { x=(x-5<0) ? 3 : x-5; $('#myList li').not(':lt('+x+')').hide(); }); });O vea la demostración y el código completo aquí: http://jsfiddle.net/oscar11/6FzSb/4177/
yo uso jquery 3.0.1
Cuando se ejecuta, existe un error:
TypeError: $(...).length no es una función
¿Cómo puedo resolverlo?
En lugar de esto
$("#myList li").length();Utilizar este:
$("#myList li").length; El $("#myList li") devuelve un objeto similar a una matriz. Todos los objetos tipo matriz tienen una propiedad llamada length , que cuando se lee devuelve el número de elementos contenidos en el objeto tipo matriz. Dicho esto, no hay ninguna función llamada longitud. Por lo tanto length() no tiene sentido.
length es una propiedad, no una función, así que elimine el ()
$("#myList li").length;length no es una función, es solo Yourthings.length sin (). más doc en documentación extensa